package com.share.hystrix;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * author:caifan
 * date:2019/7/14
 * 没有实现回退
 * 当故障、拒绝、短路等发生时，也会发生“快速故障”
 */
public class CommandThatFailsFast extends HystrixCommand<String> {
    private final boolean throwException;

    public CommandThatFailsFast(boolean throwException) {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
        this.throwException = throwException;
    }

    @Override
    protected String run() throws Exception {
        if (throwException) {
            throw new RuntimeException("failure from CommandThatFailsFast");
        } else {
            return "success";
        }
    }

//    @Override
//    protected String getFallback() {
//        return "command fail";
//    }
}
